package com.chinaexpresscard.action;

import com.chinaexpresscard.MybatisLogBinder;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;

/**
 * Created by nieqiurong on 2016/11/16.
 */
public class CopyLogStatementAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent anActionEvent) {
        Editor mEditor = anActionEvent.getData(PlatformDataKeys.EDITOR);
        SelectionModel model = mEditor.getSelectionModel();
        String selectedText = model.getSelectedText();
        if (null != selectedText && !"".equals(selectedText)) {
            String sql = MybatisLogBinder.bind(selectedText);
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(new StringSelection(sql), null);
        }
    }
}
